'''
第一步，加奖励力度和不加奖励力度的投票率
奖励力度分别为0.2,0.4,0.6，
初始投票几率为0.6
'''
import random
'''
不做任何处理，只存在诱惑力度
所有票数，计算好的票数
'''
def get_random(rate):
    i = random.randint(-1000000000,100000000)%100
    if i<(100*rate):
        return 1
    else:
        return 0

def init(people,rate):
    a=[]     #投票结果
    for i in range(people):
        a.append(get_random(rate[i]))    #根据比例生成随机数
    return a


def vote(Rate, people, round, growth,status):
    rate = [Rate]*people
    a=init(people,rate)    #第一轮投票
    result = []
    result.append(a.count(1) / people)    #people中第一轮的投票率

    for i in range(1,round+1):
        for i in range(len(a)):
            if a[i]==1 and status==1:   #投票并且是增加了奖励力度的机制
                rate[i] = rate[i]+growth
            else:
                rate[i] = rate[i]-growth    #投票率一直在减少
        a = init(people,rate)
        result.append(a.count(1)/people)
    return result


if __name__ == '__main__':
    rate = 0.6#初始投票率为0.6

    people = 1000
    round = 15
    growths =[0.2,0.4,0.6]#诱惑影响力度
    status=1    #增加奖励力度
    print('有奖励力度:')
    for growth in growths:
        a = vote(rate, people, round, growth*0.05,status)
        print(a)
    status=0
    print('没有奖励力度(原始情况):')
    for growth in growths:
        a = vote(rate, people, round, growth*0.05,status)
        print(a)